package com.yanqu.road.server.cmd.activity.chinesechess;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ChineseChessProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.chess.ChineseChessPracticeModule;
import com.yanqu.road.server.manger.activity.chinesechess.ChineseChessMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CHINESECHESS_GAME_OPERATE_PRACTICE, desc = "")
public class ChineseChessOperatePracticeCmd extends AbstractCommand {

    private int activityId;
    private int gameNo;
    private int type;
    private int skinId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ChineseChessProto.ChineseChessGameOperateReqMsg reqMsg = ChineseChessProto.ChineseChessGameOperateReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        gameNo = reqMsg.getGameNo();
        type = reqMsg.getType();
        skinId = reqMsg.getSkinId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(ChineseChessMgr.getShowTimeActivityId() == 0 || ChineseChessMgr.getShowTimeActivityId() != activityId){
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        ret = player.getModule(ChineseChessPracticeModule.class).gameOperate(activityId,gameNo,type,skinId);

    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            ChineseChessProto.ChineseChessGameOperatePracticeRespMsg.Builder respMsg = ChineseChessProto.ChineseChessGameOperatePracticeRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_CHINESECHESS_GAME_OPERATE_PRACTICE, respMsg);
        }
    }

}
